import axios from "./axios";
import Qs from "qs";
let instance = axios();
export default {
  get(url, params, headers) {
    let options = {};
    if (params) {
      options.params = params;
    }
    if (headers) {
      options.headers = headers;
    }
    return instance.get(url, options);
  },
  gets(url, params, headers) {
    let options = {};
    if (params) {
      options.params = params;
    }
    if (headers) {
      options.headers = headers;
    }
    return instance.get(url, params, options);
  },
  post(url, params, headers) {
    let options = {};
    if (params) {
      params = JSON.stringify(params);
    }
    if (headers) {
      options.headers = headers;
    }
    return instance.post(url, params, options);
  },
  posts(url, params, headers) {
    let options = {};
    if (params) {
      params = Qs.stringify(params);
    }
    if (headers) {
      options.headers = headers;
    }
    return instance.post(url, params, options);
  },
  put(url, params, headers) {
    let options = {};
    if (headers) {
      options.headers = headers;
    }
    return instance.put(url, params, options);
  },
  delete(url, params, headers) {
    let options = {};
    if (params) {
      options.params = params;
    }
    if (headers) {
      options.headers = headers;
    }
    return instance.delete(url, options);
  },
};
